//package com.ruoyi.quartz.task;
//
//import cn.hutool.http.HttpUtil;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.ruoyi.common.core.domain.entity.SysDictData;
//import com.ruoyi.common.utils.StringUtils;
//import com.ruoyi.csyc.service.*;
//import com.ruoyi.system.service.ISysDictDataService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.BeanUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.text.DecimalFormat;
//import java.util.Date;
//import java.util.List;
//import java.util.Random;
//import java.util.UUID;
//
///**
// * 定时任务调度测试
// *
// * @author ruoyi
// */
//@Component("ryTask")
//@Slf4j
//public class RyTask {
//
////    @Autowired
////    private TeaEquipmentService teaEquipmentService;
////
////    @Autowired
////    private TeaEquipmentWarnService teaEquipmentWarnService;
////
////    @Autowired
////    private ISysDictDataService dictDataService;
////
////    @Autowired
////    private TeaCoHisService teaCoHisService;
////    @Autowired
////    private TeaSoilHisService teaSoilHisService;
////    @Autowired
////    private TeaPhotovoltaicHisService teaPhotovoltaicHisService;
////
////    //    @Value("${topic.csyc_photovoltaic}")
////    private String url = "http://121.40.138.102:3821/command/send?deviceIds=01,02,03";
////
////
////    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) {
////        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
////    }
////
////    public void ryParams(String params) {
////        System.out.println("执行有参方法：" + params);
////    }
////
////    public void clearTime() {
////        teaEquipmentService.clearTime();
////    }
////
////    @Transactional(rollbackFor = Exception.class)
////    public void saveOffline() {
////        SysDictData sysDictData = new SysDictData();
////        sysDictData.setDictType("equipment_type");
////        List<SysDictData> sysDictDataList = dictDataService.selectDictDataList(sysDictData);
////        if (CollectionUtils.isNotEmpty(sysDictDataList)) {
////            for (SysDictData dictData : sysDictDataList) {
////                LambdaQueryWrapper<TeaEquipment> queryWrapper = new LambdaQueryWrapper<>();
////                queryWrapper.eq(TeaEquipment::getEquipmentType, dictData.getDictValue());
////                //获取设备最后一次发送消息 id
////                queryWrapper.select(TeaEquipment::getLatestDataId, TeaEquipment::getEquipmentState, TeaEquipment::getCodeEquipment, TeaEquipment::getCreateTime);
////                List<TeaEquipment> lastId = teaEquipmentService.list(queryWrapper);
////                Date lastDate = null;
////                for (TeaEquipment teaEquipment : lastId) {
////                    if (StringUtils.isEmpty(teaEquipment.getLatestDataId())) {
////                        long time = System.currentTimeMillis() - teaEquipment.getCreateTime().getTime();
////                        offline(sysDictData, time, teaEquipment);
//////                        if (teaEquipment.getEquipmentState() == 1 ){
//////                            teaEquipmentService.update(new UpdateWrapper<TeaEquipment>()
//////                                    .eq("code_equipment" , teaEquipment.getCodeEquipment())
//////                                    .set("equipment_state" , 0));
//////                        }
//////                        continue ;
////                    }
////                    switch (dictData.getDictValue()) {
////                        case "0":
////                            lastDate = teaCoHisService.getById(teaEquipment.getLatestDataId()).getCreateTime();
////                            break;
////                        case "1":
////                            lastDate = teaSoilHisService.getById(teaEquipment.getLatestDataId()).getCreateTime();
////                            break;
////                        case "2":
////                            lastDate = teaPhotovoltaicHisService.getById(teaEquipment.getLatestDataId()).getCreateTime();
////                            break;
////                        default:
////                            break;
////                    }
////                    if (lastDate != null) {
////                        long time = System.currentTimeMillis() - lastDate.getTime();
////                        offline(sysDictData, time, teaEquipment);
////                    }
////                }
////            }
////        }
////    }
////
////    public void offline(SysDictData sysDictData, Long time, TeaEquipment teaEquipment) {
////        sysDictData.setDictType("the_offline_time");
////        List<SysDictData> data = dictDataService.selectDictDataList(sysDictData);
////        if (time > Long.parseLong(data.get(0).getDictValue())) {
////            if (teaEquipment.getEquipmentState() == 1) {
////                teaEquipmentService.update(new UpdateWrapper<TeaEquipment>()
////                        .eq("code_equipment", teaEquipment.getCodeEquipment())
////                        .set("equipment_state", 0));
////            }
////            if (time < 14400000 && teaEquipmentWarnService.selectoffice(teaEquipment.getCodeEquipment()) < 3) {
////                TeaEquipmentWarn teaEquipmentWarn = getTeaEquipmentWarn(teaEquipment.getCodeEquipment());
////                teaEquipmentWarn.setEquipmentMessag("设备离线");
////                teaEquipmentWarnService.save(teaEquipmentWarn);
////            }
////        }
////    }
////
////    public void getCommandSend() {
////        //可以单独传入http参数，这样参数会自动做URL编码，拼接在URL中
////        log.info("光伏调用地址:{}", url);
////        String s = HttpUtil.get(url);
////        log.info("光伏回调:{}", s);
//////        JSONObject jsonObject = JSONObject.parseObject(s);
//////        Object code = jsonObject.get("code");
//////        Object msg = jsonObject.get("msg");
//////        log.info("调用光伏接口返回值Code: " + code + " ------- "+" msg: " + msg);
////    }
////
////    public TeaEquipmentWarn getTeaEquipmentWarn(String code) {
////        TeaEquipmentWarn teaEquipmentWarn = new TeaEquipmentWarn();
////        teaEquipmentWarn.setEquipmentId(code);
////        teaEquipmentWarn.setEquipmentCode(UUID.randomUUID().toString());
////        teaEquipmentWarn.setAlarmMethed(0L);
////        teaEquipmentWarn.setEquipmentStatus(0L);
////        teaEquipmentWarn.setAlarmType(1L);
////        return teaEquipmentWarn;
////    }
////
////    @Transactional(rollbackFor = Exception.class)
////    public void gennerateCo2Data() {
////        TeaCoHis one = teaCoHisService.getOne(Wrappers.<TeaCoHis>lambdaQuery().orderByDesc(TeaCoHis::getCreateTime).eq(TeaCoHis::getSensorCode, "33082210217").last("limit 1"));
////        TeaCoHis teaCoHis = new TeaCoHis();
////        BeanUtils.copyProperties(one, teaCoHis);
////        teaCoHis.setCreateTime(new Date());
////        teaCoHis.setSendTime(new Date());
////        teaCoHis.setCo2Concentration(randomDouble());
////        teaCoHis.setId(UUID.randomUUID().toString());
////        teaCoHisService.save(teaCoHis);
////
////    }
////
////    public Double randomDouble() {
////        Random random = new Random();
////        int i = random.nextInt(10);
////        double random1 = Math.random();
////        DecimalFormat df = new DecimalFormat("#.0");
////        double ss = 400 + i+random1;
////        Double aDouble = Double.valueOf(df.format(ss));
////        return aDouble;
////    }
//}
